package io.jpress.service.provider;

import io.jboot.aop.annotation.Bean;
import io.jpress.commons.service.JPressServiceBase;
import io.jpress.model.Department;
import io.jpress.service.DepartmentService;

@Bean
public class DepartmentServiceProvider extends JPressServiceBase<Department> implements DepartmentService {

    @Override
    public boolean deleteByIds(Object[] ids) {
        if (ids != null) {
            for (Object id : ids) {
                deleteById(id);
            }
        }
        return true;
    }


    @Override
    public Department findByUserId(Long userId) {
        String sql = "select * from department d " +
                    " left join user_department_mapping udm on d.id = udm.department_id " +
                    " where udm.user_id = ?";
        return DAO.findFirst(sql,userId);
    }

}